<?php
/**
 *
 * @authors Your Name (you@example.org)
 * @date    2018-05-08 14:01:29
 * @version $Id$
 */
/**
 * 游戏操作
 * select id,logtime,playername,src,nowvc ,CONCAT('+',addvc) as addvc  from tab_vconin_add  union all select id,logtime,playername,src,nowvc,CONCAT('-',addvc) as addvc from tab_vconin_rem
 *
 *
 *select t.* from (
select id ,name from test1
union
select id, name from test 2
) t where t.id = 4
limit 1
 * *
 *
 */
namespace app\admin\controller;

use Request;

class GameLog extends Base
{
    private $partitionid; //当前区id
    public function initialize()
    {
        parent::initialize();
        $this->partitionid = session('partitionid'); //别名：避免与控制名冲突
        if (empty($this->partitionid)) {return $this->error('参数错误,请先选择分区，然后再操作', 'Partition/index');}

    }

    public function index()
    {
        $id = $this->request->has('id') ? $this->request->param('id', 0, 'intval') : 0;
        return $this->fetch();
    }
    /**
     * 在线人数日志
     * @return [type] [description]
     */
    public function online($begnday = '')
    {
        $id = $this->partitionid;
        //if (empty($id)) {return $this->error('参数错误');}
        if (!CreateGameModel($id, 'log')) {
            return $this->error('请先正确配置数据库信息', 'Partition/index');
        }
        $begnday = !empty($begnday) ? trim($begnday) : date('Y-m-d');
        $endnday = date('Y-m-d', strtotime('+1 day', strtotime($begnday))); //当前时间加1天

        $yesterday = date('Y-m-d', strtotime('-1 day', strtotime($begnday))); //昨天

        $weekday = date('Y-m-d', strtotime('-7 day', strtotime($begnday))); //7天内

        $where   = [];
        $where[] = ['logtime', 'between', [$begnday, $endnday]];

        $field = "DATE_FORMAT(logtime ,'%H') as g_hour,Max(online_reg) as f_max";
        $list  = CreateGameModel($id, 'log')->table('tab_online')->field($field)->group('g_hour')->where($where)->order('id', 'asc')->select();

        $yesterdaycount = CreateGameModel($id, 'log')->table('tab_online')->field("Max(online_reg) as u_max")->whereBetweenTime('logtime', $yesterday, $begnday)->find();
        $weekaycount    = CreateGameModel($id, 'log')->table('tab_online')->field("Max(online_reg) as u_max")->whereBetweenTime('logtime', $weekday, $begnday)->find();
        $daycount       = CreateGameModel($id, 'log')->table('tab_online')->field("Max(online_reg) as u_max")->where($where)->order('id', 'desc')->find();

        $nowdaycount = CreateGameModel($id, 'log')->table('tab_online')->field("online_reg as u_max")->order('id', 'desc')->find();
        //print_r($weekaycount);
        $g_hour = [];
        $f_max  = [];
        foreach ($list as $v) {
            $g_hour[] = $v['g_hour'];
            $f_max[]  = $v['f_max'];
        }
        $this->assign([
            'id'             => $id,
            'hour'           => implode(",", $g_hour),
            'max'            => implode(",", $f_max),
            'begnday'        => $begnday,
            'yesterdaycount' => $yesterdaycount,
            'weekaycount'    => $weekaycount,
            'daycount'       => $daycount,
            'nowdaycount'    => $nowdaycount,

        ]);
        return $this->fetch();
    }

    /**
     * 元宝消费日志
     * @return [type] [description]
     */
    public function consume($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxconsume($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = '';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_consume')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_consume')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();
        $list  = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
        //return $this->ajaxlist($search, $searchdate, $val, 1, $limit, 'tab_consume');

    }

    /**
     * 物品交易日志
     * @return [type] [description]
     */
    public function trade($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxtrade($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {

        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,tradeG as tradeg,tradeM as tradem,mTypeID as mtypeid,mPosition as position,mDuraMax as dmax,mDuration as jmax';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_trade')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_trade')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();
        foreach ($list as $k => $v) {
            $list[$k]['mtypeid'] = \Db::name('itemdef')->where('wid', $v['mtypeid'])->value('name') ?? $v['mtypeid']; //关联物品
            $list[$k]['mtypeid'] = $v['mtypeid'].'|'.$list[$k]['mtypeid'];
        }
        $list = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 金币交易日志
     * @return [type] [description]
     */
    public function tradegm($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxtradegm($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,tradeG as tradeg,tradeM as tradem,monegy';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_tradegm')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_tradegm')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();
        $list  = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

/**
 * 元宝交易日志
 * @return [type] [description]
 */
    public function tradevc($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxtradevc($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,tradeG as tradeg,tradeM as tradem,vcoin';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_tradevc')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_tradevc')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();
        $list  = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 元宝增加总表
     * @return [type] [description]
     */
    public function vconinadd($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxvconinadd($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername,src,addvc,nowvc';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_vconin_add')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_vconin_add')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();

        $srcarr = writeSrctxt('vconinadd');
        if ($srcarr) {
            foreach ($list as $k => $v) {
                foreach ($srcarr as $sk => $sv) {
                    if ($v['src'] == $sv[0] && !empty($sv[1])) {
                        $list[$k]['src'] = $sv[1]; //关联物品
                    }
                }
            }
        }

        $list  = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 元宝减少总表
     * @return [type] [description]
     */
    public function vconinrem($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxvconinrem($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data   = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field  = 'id,logtime,playername,src,addvc,nowvc';
        $count  = CreateGameModel($data['uid'], 'log')->table('tab_vconin_rem')->where($data['where'])->count();
        $list   = CreateGameModel($data['uid'], 'log')->table('tab_vconin_rem')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();
        
        $srcarr = writeSrctxt('vconinrem');
        if ($srcarr) {
            foreach ($list as $k => $v) {
                foreach ($srcarr as $sk => $sv) {
                    if ($v['src'] == $sv[0] && !empty($sv[1])) {
                        $list[$k]['src'] = $sv[1]; //关联物品
                    }
                }
            }
        }
        $list = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 绑定元宝增加总表
     * @return [type] [description]
     */
    public function vcoinbindadd($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxvcoinbindadd($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername,src,addvc,nowvc';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_vcoinbind_add')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_vcoinbind_add')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();

        $srcarr = writeSrctxt('vcoinbindadd');
        if ($srcarr) {
            foreach ($list as $k => $v) {
                foreach ($srcarr as $sk => $sv) {
                    if ($v['src'] == $sv[0] && !empty($sv[1])) {
                        $list[$k]['src'] = $sv[1]; //关联物品
                    }
                }
            }
        }

        $list = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    public function vconin($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }
/*
    public function ajaxvconin($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        //$field = 'id,addvc,logtime,playername,src,nowvc';
        $von = $this->request->has('von') ? $this->request->param('von') : "";
        // $count = CreateGameModel($data['uid'], 'log')->table('tab_vconin_rem')->where($data['where'])->count();
        if ($von == 'add') {
            //echo "ddd";
            $field = 'CONCAT("a-",id) as id,addvc,logtime,playername,src,nowvc';
            $count = CreateGameModel($data['uid'], 'log')->table('tab_vconin_add')->where($data['where'])->count();
            $list  = CreateGameModel($data['uid'], 'log')->table('tab_vconin_add')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('logtime', 'desc')->select();
        } else if ($von == 'rem') {
            //echo "dssdd---".$von;
            $field = 'CONCAT("r-",id) as id,addvc,logtime,playername,src,nowvc';
            $count = CreateGameModel($data['uid'], 'log')->table('tab_vconin_rem')->where($data['where'])->count();
            $list  = CreateGameModel($data['uid'], 'log')->table('tab_vconin_rem')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('logtime', 'desc')->select();
        } else {
            //print_r($data['where']);
            // foreach ($data['where'] as $key => $v) {
            //     $whe[] = $v['0'] ." ". $v['1'] ." ".$v['2'];
            // }
            //$wheres = implode("and", $whe);
            $field = 'CONCAT("a-",id) as id,addvc,logtime,playername,src,nowvc';
            $list  = CreateGameModel($data['uid'], 'log')
                ->table('tab_vconin_add')
                ->field($field)
                ->unionAll('SELECT CONCAT("r-",id) as id,CONCAT("-",addvc) as addvc,logtime,playername,src,nowvc FROM tab_vconin_rem')
                //->unionAll('SELECT CONCAT("a-",id) as id,CONCAT("+",addvc) as addvc,logtime,playername,src,nowvc FROM tab_vconin_add')
                ->where($data['where'])->page($data['page'], $data['limit'])->order('logtime', 'desc')->select();
            $count = CreateGameModel($data['uid'], 'log')->table('tab_vconin_add')->where($data['where'])->count() + CreateGameModel($data['uid'], 'log')->table('tab_vconin_rem')->where($data['where'])->count();
        }

        $list = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }
*/
    /**
     * 绑定元宝减少总表
     * @return [type] [description]
     */
    public function vconinbindrem($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxvconinbindrem($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername,src,addvc,nowvc';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_vconinbind_rem')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_vconinbind_rem')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();

        $srcarr = writeSrctxt('vconinbindrem');
        if ($srcarr) {
            foreach ($list as $k => $v) {
                foreach ($srcarr as $sk => $sv) {
                    if ($v['src'] == $sv[0] && !empty($sv[1])) {
                        $list[$k]['src'] = $sv[1]; //关联物品
                    }
                }
            }
        }

        $list  = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);

    }

    // /、、、、、、、、、、、、、、、、、、、、、、、、、、

    /**
     * 金币增加总表
     * @return [type] [description]
     */
    public function gamemoneyadd($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxgamemoneyadd($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername,src,addvc,nowvc';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_gamemoney_add')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_gamemoney_add')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();
        
        $srcarr = writeSrctxt('gamemoneyadd');
        if ($srcarr) {
            foreach ($list as $k => $v) {
                foreach ($srcarr as $sk => $sv) {
                    if ($v['src'] == $sv[0] && !empty($sv[1])) {
                        $list[$k]['src'] = $sv[1]; //关联物品
                    }
                }
            }
        }

        $list = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 金币减少总表
     * @return [type] [description]
     */
    public function gamemoneyrem($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxgamemoneyrem($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername,src,addvc,nowvc';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_gamemoney_rem')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_gamemoney_rem')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();

        $srcarr = writeSrctxt('gamemoneyrem');
        if ($srcarr) {
            foreach ($list as $k => $v) {
                foreach ($srcarr as $sk => $sv) {
                    if ($v['src'] == $sv[0] && !empty($sv[1])) {
                        $list[$k]['src'] = $sv[1]; //关联物品
                    }
                }
            }
        }       
        $list  = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 绑定金币增加总表
     * @return [type] [description]
     */
    public function gamemoneybindadd($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxgamemoneybindadd($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername,src,addvc,nowvc';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_gamemoneybind_add')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_gamemoneybind_add')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();

        $srcarr = writeSrctxt('gamemoneybindadd');
        if ($srcarr) {
            foreach ($list as $k => $v) {
                foreach ($srcarr as $sk => $sv) {
                    if ($v['src'] == $sv[0] && !empty($sv[1])) {
                        $list[$k]['src'] = $sv[1]; //关联物品
                    }
                }
            }
        }         
        $list  = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 绑定金币减少总表
     * @return [type] [description]
     */
    public function gamemoneybindrem($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxgamemoneybindrem($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername,src,addvc,nowvc';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_gamemoneybind_rem')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_gamemoneybind_rem')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();

        $srcarr = writeSrctxt('gamemoneybindrem');
        if ($srcarr) {
            foreach ($list as $k => $v) {
                foreach ($srcarr as $sk => $sv) {
                    if ($v['src'] == $sv[0] && !empty($sv[1])) {
                        $list[$k]['src'] = $sv[1]; //关联物品
                    }
                }
            }
        } 

        $list  = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 玩家等级变更记录
     * @return [type] [description]
     */
    public function level($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxlevel($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername,lv';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_level')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_level')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();
        $list  = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * GM命令表
     * @return [type] [description]
     */
    public function gmcmd($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxgmcmd($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername,cmd';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_gmcmd')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_gmcmd')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();
        $list  = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 沙城工会记录
     * @return [type] [description]
     */
    public function kingguild($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxkingguild($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_kingguild')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_kingguild')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();
        $list  = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 物品增加
     * @return [type] [description]
     */
    public function itemadd($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxitemadd($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername,mTypeID as mtypeid,mPosition as position,mIdentID as midentid,mUpdCount as mupdcount';
        // $field = '';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_item_add')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_item_add')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();
        foreach ($list as $k => $v) {
            $list[$k]['mtypeid'] = \Db::name('itemdef')->where('wid', $v['mtypeid'])->value('name') ?? $v['mtypeid']; //关联物品
            $list[$k]['mtypeid'] = $v['mtypeid'].'|'.$list[$k]['mtypeid'];
        }
        $list = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 物品减少
     * @return [type] [description]
     */
    public function itemrem($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxitemrem($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername,mTypeID as mtypeid,mPosition as position,mIdentID as midentid,mUpdCount as mupdcount';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_item_rem')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_item_rem')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();
        foreach ($list as $k => $v) {
            $list[$k]['mtypeid'] = \Db::name('itemdef')->where('wid', $v['mtypeid'])->value('name') ?? $v['mtypeid']; //关联物品
        }
        $list = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 物品变化后余多少
     * @return [type] [description]
     */
    public function itemnum($search = '', $val = '', $searchdate = '')
    {
        return $this->showlist($search, $val, $searchdate);
    }

    public function ajaxitemnum($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $data  = $this->ajaxlist($search, $searchdate, $val, $page, $limit);
        $field = 'id,logtime,playername,mTypeID as mtypeid,mPosition as position,mIdentID as midentid,mUpdCount as mupdcount';
        $count = CreateGameModel($data['uid'], 'log')->table('tab_item_num')->where($data['where'])->count();
        $list  = CreateGameModel($data['uid'], 'log')->table('tab_item_num')->field($field)->where($data['where'])->page($data['page'], $data['limit'])->order('id', 'desc')->select();
        foreach ($list as $k => $v) {
            $list[$k]['mtypeid'] = \Db::name('itemdef')->where('wid', $v['mtypeid'])->value('name') ?? $v['mtypeid']; //关联物品
        }
        $list = ["code" => 0, "msg" => "加载中", "count" => $count, "data" => $list];
        return json($list);
    }

    /**
     * 基础数据
     * @param  string $search     [description]
     * @param  string $val        [description]
     * @param  string $id         [description]
     * @param  string $searchdate [description]
     * @return [type]             [description]
     */
    private function showlist($search = '', $val = '', $searchdate = '', $von = '')
    {
        $id = $this->partitionid;
        if (!CreateGameModel($id, 'log')) {
            return $this->error('请先正确配置日志数据库信息', 'Partition/index');
        }
        $search     = trim($search) ?? '';
        $val        = trim($val) ?? '';
        $searchdate = trim($searchdate) ?? '';
        //echo $searchdate;
        $this->assign([
            'id'         => $id,
            'search'     => $search,
            'val'        => $val,
            'searchdate' => $searchdate,
            'von'        => trim($von) ?? '',
        ]);
        return $this->fetch();
    }

    private function ajaxlist($search = '', $searchdate = '', $val = '', $page = 1, $limit = '')
    {
        $id = $this->partitionid;
        //if (empty($id)) {return $this->error('参数错误');}
        if (!CreateGameModel($id, 'log')) {
            //增加安全，有点影响性能
            return $this->error('请先正确配置日志数据库信息', 'Partition/index');
        }
        $where = [];

        $search     = trim($search) ?? '';
        $val        = trim($val) ?? '';
        $limit      = trim($limit) ?? config('webconfig.page');
        $searchdate = trim($searchdate) ?? '';

        if ($searchdate && $searchdate != '-') {
            $searchdate = explode(" - ", $searchdate);
            $where[]    = ['logtime', 'between', [$searchdate[0], $searchdate[1]]];
        }
        if ($search && $val) {
            if (preg_match("/[\x7f-\xff]/", $val)) {
                $where[] = [$search, 'like', '%' . $val . '%'];
            } else {
                $where[] = [$search, '=', $val];
            }
        }

        $page = !empty($page) ? $page : 1;
        return [
            'uid'   => $id,
            //'table'  => $table,
            //'field'  => $field,
            'where' => $where,
            'page'  => $page,
            'limit' => $limit,

        ];
    }

}
